package servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import bean.Goods;
import dao.ListGoods;
import dao.SoldOutMethod;

/**
 * Servlet implementation class AdminSoldOutServlet
 * 管理员使商品下架
 */
public class AdminSoldOutServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AdminSoldOutServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		String idString = request.getParameter("id");
		String pageString = request.getParameter("page");
		int id = Integer.parseInt(idString);
		int page = Integer.parseInt(pageString);
		SoldOutMethod.soldOut(id);
		
		List<Goods> list;
		list = ListGoods.getListGoods("select * from goods where goods_state=1 order by goods_id desc limit "+(page-1)*25+",25");//执行具体获取方法

		request.setAttribute("list", list);//将结果放入request
		request.setAttribute("page", page);
		
		request.getRequestDispatcher("/admin/view/index.jsp").forward(request,
				response);
		return;
	}

}
